<%@ page language="java" contentType="text/html; charset=UTF-8" import="java.util.*,com.device.operating.entity.*,com.device.operating.vo.*"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="/xasj/css/jquery-ui.min.css">
<link rel="stylesheet" type="text/css" href="/xasj/css/smartMenu.css">
<script type="text/javascript" src="/xasj/easyui/jquery.min.js"></script>
<script type="text/javascript"src="/xasj/js/common/jquery-smartMenu.js"></script>
<script type="text/javascript" src="../xasj/js/common/jquery-ui-1.9.2-min.js"></script>
<script type="text/javascript" src="../xasj/js/common/jquery.jsPlumb-1.4.0-all.js"></script>
<script type="text/javascript" src="../xasj/js/other/ping.js"></script>
<!-- <script type="text/javascript" src="/xasj/js/common/jquery.easyui.min.js"></script> -->
<%
List<Dvrela> list=new ArrayList<Dvrela>();
List<Dvcommon> listdv=new ArrayList<Dvcommon>();
int[] dvcount=new int[6];
if(request.getAttribute("list")!=null){
	list=(List<Dvrela>)request.getAttribute("list");
}
if(request.getAttribute("listdv")!=null){
	listdv=(List<Dvcommon>)request.getAttribute("listdv");
}

%>
   <style type="text/css">
        .dragActive { border:2px dotted orange; }
        .dropHover { border:1px dotted red; }
        .item {
        	text-align:center;     	
            border: 1px solid #00FF00;
            border-bottom:5px solid #00FF00;
            background-color: #F2F2F2;
            font-size:12px;
            width: 110px;
            height: 40px;
            position: absolute;
        }
        .itemolt {
        	text-align:center;     	
            border: 1px solid #00FF00;
            border-bottom:5px solid #00FF00;
            background-color: #F2F2F2;
            font-size:12px;
            width: 110px;
            height: 70px;
            position: absolute;
        }
        .dvfort {font-size: 11px}
    </style>
    <script>
    /*
    $.ping({
    	url : '36.42.32.67', 
    	beforePing : function(){
    	$('#msg1').html('')
    	},
    	afterPing : function(ping){
    	if(ping<20){
    		$('#ceshi').css("border-bottom","3px #f00 solid");
    	}else{
    		$('#ceshi').css("border-bottom","3px #000 solid");
    	}
    	$('#msg').html(ping);
    	}, 
    	interval : 1
    });*/
	
	jsPlumb.ready(function() {
		jsPlumb.importDefaults({
			  PaintStyle : {
			    lineWidth:3,
			    strokeStyle: 'rgba(200,0,0,0.5)'
			  },
			  DragOptions : { cursor: "crosshair" },
			  Endpoints : [ [ "Dot", { radius:3 } ], [ "Dot", { radius:3 } ] ],
			  EndpointStyles : [{ fillStyle:"rgba(200,0,0,0.5)" }, { fillStyle:"rgba(200,0,0,0.5)" }]
			});
		 <%if(request.getAttribute("listdv")!=null){
			for(Dvcommon dv:listdv){//选定的设备，第一次显示
			%>
			$('#'+'<%=dv.getDvId()%>').css("border-bottom","6px #00FF00 solid");
<%-- 			    $.ping({
			    	url:'<%=dv.getDvip()%>', 
			    	beforePing : function(){			    	
			    	},
			    	afterPing : function(ping){
			    		ping=$('#'+'<%=dv.getDvId()%>').html(ping);
			    	$('#'+'<%=dv.getDvId()%>').html(ping);
			    	if(ping<50){
			    		$('#'+'<%=dv.getDvId()%>').css("border-bottom","6px #00FF00 solid");
			    	}else if(ping>=50&&ping<200){
			    		$('#'+'<%=dv.getDvId()%>').css("border-bottom","6px #9CFF00 solid");
			    	}else if(ping>=200&&ping<500){
			    		$('#'+'<%=dv.getDvId()%>').css("border-bottom","6px #FFEA00 solid");
				    }else if(ping>=500&&ping<2000){
				    	$('#'+'<%=dv.getDvId()%>').css("border-bottom","6px #FFA800 solid");
				    }else if(ping>=500&&ping<5000){
				    	$('#'+'<%=dv.getDvId()%>').css("border-bottom","6px #FF4800 solid");
					}else{
						$('#'+'<%=dv.getDvId()%>').css("border-bottom","6px #000000 solid");
					}			    	
			    	}, 
			    	interval : 1
			    }); --%>
		 	jsPlumb.draggable("<%=dv.getDvId()%>");	
		 <%}%>
       <%for(Dvrela dvrela:list){%>
       	jsPlumb.connect({
    	   	anchors:["TopCenter","BottomCenter"],
    	   	source:"<%=dvrela.getDvId()%>",
    	   	target:"<%=dvrela.getParentId()%>",
    	   	connector:"Straight",
    	   	hoverPaintStyle:{lineWidth:7},
    	   	});
       	<%}%>
       	jsPlumb.bind("contextmenu",function (conn, originalEvent) {
       		originalEvent.preventDefault();
       		//alert(conn.sourceId);
            parent.parent.addTab('编辑设备上联','toeditparent?dvId='+conn.sourceId);	
         });
       	jsPlumb.bind("click",function (conn, originalEvent) {     
            //alert(conn.sourceId+","+conn.targetId); 
   			//alert('OK');
   			//$('#showparent').dialog({
   	   			//title:'设备上联',    
   			    //href:'todvparent?dvId='+conn.sourceId+'&parentId='+conn.targetId,    
   			    //onLoad:function(){    
   			    	//$.getScript('/xasj/js/component/dvparent.js');    
   			    //},   
   			//});
   			//$('.panel datagrid').after('<div><a id="comaddparent" style="width:100px"></a></div>');
   			//$('.panel datagrid').after('<div><a id="comaddparent" style="width:100px"></a></div>');
   			//alert($('.panel datagrid')); 
   			$( "#showparent" ).dialog({
       			width:600,
       			height:350,
       		 	title:"设备连接",           		
             	buttons: { "关闭": function() { $(this).dialog("close"); } }  
         	});
   			$.ajax({
				url:'showdvparent?dvId='+conn.sourceId+'&parentId='+conn.targetId,
				success:function(data){
					$('#showparent').empty();
					var ds=data.rows;
					var newhtm='<table>';
					for(var i=0;i<ds.length;i++){
						newhtm=newhtm+'<tr><td width="180">'+ds[i].dvname+'('+ds[i].dvip+')</td><td width="100">'+ds[i].dvslot+
						'</td><td width="180">'+ds[i].parentname+'('+ds[i].parentip+')</td><td width="100">'+ds[i].parentslot+
						'</td></tr>';
					}
					newhtm=newhtm+'</table>';
					$('#showparent').append(newhtm);
			}
   	   		});
   		jsPlumb.bind("dbclick",function (conn, originalEvent) {
   			alert('ok');
   			parent.addTab('添加IP资源','toaddipres');				
   	   	 });

   						
       		//$( "#showparent" ).dialog({ 
              //  buttons: { "Ok": function() { $(this).dialog("close"); } }  
           //});
         });
       	jsPlumb.bind("mouseover",function (conn, originalEvent) {     
            alert('ok');     
         });
		 <%}%>
		 
		 $('#showparent').css('z-index','99999');
		 $('.item').css('z-index','88');
		 $(window.parent.document).find("#jxmap").load(function(){
			 var jxmap = $(window.parent.document).find("#jxmap");
			 var thisheight = $(document).height()+80;
			 jxmap.height(thisheight);
		});
		$('.item').bind('dblclick',function(){
//				alert($(this).data('ip'));	
//				runcommand();
			var ip=$(this).data('ip');
			var p_file_path= getCookie('my_crt_path');//CRT路径
				if(p_file_path==null || p_file_path=='undefined'||p_file_path==''){
					setcrtpathcookie();
					return;
				 }
			RunExe(p_file_path,ip);
		});
	  });
</script>
</head>
<input id="dvId" value="" style="display:none"/>
<input id="dvbelong" value="" style="display:none"/>
<body>
	<div id="dvres">
 <%if(listdv.size()==0){%>
			<div>无此关联设备 </div>
 	<%}else{
 		for(Dvcommon dv:listdv){%>
 			<div id="<%=dv.getDvId()%>" data-dvbelong="<%=dv.getDvbelong()%>" data-ip="<%=dv.getDvip()%>" style="left:<%=dv.getDvleft()%>%;top:<%=dv.getDvtop()%>px
 			<%if(dv.getTopcolor()!=null){%>;border-top:5px solid #<%=dv.getTopcolor()%><%}%>" <%if(dv.getListcusercodes()==null){%>class="item"<%}else{%>class="itemolt"<%}%>>
 			
 			<%=dv.getDvname()+"("+dv.getDvbelong()+")"%><br>
 			<%=dv.getDvip()%>
 			<%if(dv.getListcusercodes()!=null){
 			List<String> listc=dv.getListcusercodes();
 			for(String cusercode:listc){%>
 				<%=cusercode%><br>
 			<%}}%>
 			</div>
 		<%}
 	}%> 
 	</div>
 	<div id="showparent"  style="display:none" class="dvfort">
 	</div>
</body>
<script type="text/javascript">
var objdetail = {
		text: "设备详细信息",
		func: function() {
			
		}	
	}, objedit = {
		text: "设备编辑",
		func: function() {
//			parent.parent.addTab('设备信息编辑','tooltedit?oltId='+$('#dvId').val());
			parent.parent.addTab('设备信息编辑','todvedit?dvId='+$('#dvId').val()+'&dvbelong='+$('#dvbelong').val(),'edit');
		}	
	}, doscript = {
		text: "设备批操作",
		data: 
			[[{
				text: "中兴H设备PPPOE+自动化部署",
				func: function() {
					
				}
			}, {
				text: "中兴H设备开局",
				func: function() {
					
				}
			}, {
				text: "清理垃圾配置",
				func: function() {
					
				}
			}, {
				text: "中兴H设备PON口分配",
				func: function() {
					
				}
			}, {
				text: "中兴H设备查看上线用户",
				func: function() {
					
				}
			}]]		
	},objUnRead = {
			text: "标记为未读",
			func: function() {
				funTrGet().css("font-weight", "700");
			}	
	};
var mailMenuData = [
                	[objdetail, objedit,doscript]
                ];
$('.item').smartMenu(mailMenuData, {
	name: "mail",
	beforeShow: function(){
		$('#dvId').val($(this).attr('id'));
		$('#dvbelong').val($(this).data('dvbelong'));
//		mailMenuData[1] = [objUnRead];
	}
});
</script>
<script>
function setcrtpathcookie(){
	document.getElementById('file1').click();
	var  p_file_path=document.getElementById('file1').value;
    if(p_file_path!=null && p_file_path!=''  && p_file_path!='undefined'){ 
      setCookie('my_crt_path',p_file_path);
      alert('路径设置完毕 请重新打开');
    }else{
      alert('您没有选择要启动的程序,所以无法启动!');
   	}
}

function setCookie(name,value)
{
    var Days = 30000000;
    var exp  = new Date();    //new Date("December 31, 9998");
        exp.setTime(exp.getTime() + Days*24*60*60*1000);
        document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}

function getCookie(sName){
// cookies are separated by semicolons
var aCookie = document.cookie.split("; ");
for (var i=0; i < aCookie.length; i++){
// a name/value pair (a crumb) is separated by an equal sign
	var aCrumb = aCookie[i].split("=");
	if (sName == aCrumb[0])
	return unescape(aCrumb[1]);
}
// a cookie with the requested name does not exist
	return null;
}

function RunExe(strPath,ip){
	try { 
	var file_path=strPath.replace(/\\/g,"/");
	var dir_path=file_path.substring(0,file_path.lastIndexOf("/")+1);
	runByVb(file_path,dir_path,ip); 
	}catch (e){
		alert('找不到文件路径和文件名不正确或者您的浏览器没有启用此ActiveX控件!');
		var r=confirm("重设CRT路径?"); 
		if(r == true){ 
			setcrtpathcookie();
		}   
	   }  
}
</script>

<script LANGUAGE="VBSCRIPT">
function runByVb(file_path,dir_path,ip)
Set objShell = CreateObject("WScript.Shell")
objShell.CurrentDirectory = dir_path
file_path=file_path+" "+ip
Set objWshScriptExec = objShell.Exec(file_path)
end function
</script>
<input type='file' id='file1' style="display: none" value=''/>
</html>